package TUILayer;
import ControlLayer.*;
import ModelLayer.*;
import java.util.Scanner;

/**
 * This is the 3th menu, Dvd menu.
 * 
 * @author (Group2) 
 * @version (2)
 */

 
public class DVDMenuUI
{
    // instance variables 
    private ControlDVD controler;

    public DVDMenuUI()
    {
        controler=new ControlDVD();
    }

    public void DVDMenu()
    {
        boolean exit=false;
        while (!exit) //! means while exit not is true (that is: false)
        {
            int choise3 = textDVDMenu();
            switch (choise3)
            {
                // Create a new dvd
                case 1:
                { String i="";
                    while (!i.equals("1"))
                    {
                        CreateDVD();

                        Scanner keyboard = new Scanner(System.in);
                        System.out.println("Press 1 to return");
                        System.out.println("Press enter to create another DVD");
                        String var=keyboard.nextLine();
                        i=var;
                    }   
                    break;

                }
                case 2:
                {
                    // update a DVD
                    updateDVDMenu();
                    break;
                }
                case 3:
                {   
                    // Remove dvd
                    Scanner keyboard = new Scanner(System.in);  
                    System.out.println("Please insert the id of the dvd you want to remove:");
                    String id=keyboard.nextLine();

                    controler.removeDVD(id);
                    break;
                }
                case 4:
                {
                    // list all the dvds
                    String i="";
                    while (!i.equals("1"))
                    {
                        Scanner keyboard = new Scanner(System.in);
                        controler.printAllDvd();
                        System.out.println("Press 1 to return");
                        System.out.println("Press enter to print the list again.");
                        String var=keyboard.nextLine();
                        i=var;
                    }
                    break;
                }
                case 5:
                {
                    // retrive more info about a dvd
                    String i=""; 
                    while (!i.equals("1"))
                    {  
                        Scanner keyboard = new Scanner(System.in);  
                        System.out.println("Please insert the id of the dvd you want more info:");
                        String id=keyboard.nextLine();

                        controler.readDVD(id);
                        System.out.println("Press 1 to return");
                        System.out.println("Press enter to print the list again.");
                        String var=keyboard.nextLine();
                        i=var;
                    }      
                    break;
                }
                case 6:
                {
                    // add copies to a dvd 
                    addCopies();
                    break;
                }
                case 7:
                {
                    // retrive a list of all copies of a dvd
                    String i="";
                    while (!i.equals("1"))
                    {
                        Scanner keyboard = new Scanner(System.in);  
                        System.out.println("Please insert the title of the dvd that you want to see all the copies:");
                        String DVDTitle=keyboard.nextLine();

                        controler.getCopiesOfDVD(DVDTitle);
                        System.out.println("Press 1 to return");
                        System.out.println("Press enter to list again.");
                        String var=keyboard.nextLine();
                        i=var;
                    }
                    break;
                }
                case 8:
                {
                    // return to the main menu
                    exit = true; 
                    break;
                }
            }

        }// end else
    }

   // Menu for updateing a dvd
    private void updateDVDMenu()
    {
        boolean exit=false;
        while (!exit) //! means while exit not is true (that is: false)
        {
            int choise3 = textUpdateDVDMenu();
            switch (choise3)
            {
                case 1:
                {
                    // update a dvd's title
                    Scanner keyboard = new Scanner(System.in);  
                    System.out.println("Please type DVD's Id that you want to change title:");
                    String id=keyboard.nextLine();

                    System.out.println("Please type the new title");
                    String title=keyboard.nextLine();

                    controler.updateDVDTitle(id,title);
                    break;
                }
                case 2:
                {
                    // update a dvd's artist
                    Scanner keyboard = new Scanner(System.in);  
                    System.out.println("Please type DVD's Id that you want to change artist:");
                    String id=keyboard.nextLine();

                    System.out.println("Please type the new artist");
                    String artist=keyboard.nextLine();

                    controler.updateDVDArtist(id,artist);
                    break;

                }
                case 3:
                { 
                   // update a dvd's publication date
                    Scanner keyboard = new Scanner(System.in);  
                    System.out.println("Please type DVD's Id that you want to change publication date:");
                    String id=keyboard.nextLine();

                    System.out.println("Please type the new artist");
                    String PublicationDate=keyboard.nextLine();

                    controler.updateDVDPublicationDate(id,PublicationDate);
                    break;

                }
                case 4:
                {
                    //return to the dvd menu
                    DVDMenu();
                    exit = true;        
                    break;

                }

            }
        }
    }

   
    public int textUpdateDVDMenu()
    {
        // creates a keyboard object to read input
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** UpdateDVD Menu ***");
        System.out.println(" Chose what do you want to modify");
        System.out.println(" (1)Title");
        System.out.println(" (2)Artist");
        System.out.println(" (3)Publication Date");
        System.out.println(" (4)Return");
        System.out.print("\n Make your choise: ");

        int choise3 = keyboard.nextInt();

        return choise3;
    }
    
    // display what info you should type in order to add a copy to a dvd
    public void addCopies()
    {
        Scanner keyboard = new Scanner(System.in);

        System.out.println(" Write DVDId:");
        String DVDId=keyboard.nextLine();

        System.out.println(" Write serial number:");
        int serialNumber=keyboard.nextInt();
        keyboard.nextLine();

        System.out.println(" Write purchase date:");
        String purchaseDate=keyboard.nextLine();
        
         System.out.println(" Write purchase price");
        int purchasePrice=keyboard.nextInt();
        
        String state="available";

        controler.addCopiesToDVD(DVDId,serialNumber,purchaseDate,purchasePrice,state);
    }
        
        // display what info you should type in order to create a dvd
    private void CreateDVD()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Write id:");
        String id=keyboard.nextLine();

        System.out.println(" Write title:");
        String title=keyboard.nextLine();

        System.out.println(" Write artist:");
        String artist=keyboard.nextLine();

        System.out.println(" Write publication date");
        String publicationDate=keyboard.nextLine();

        controler.createDVD(id, title, artist, publicationDate);

    }

        
    private int textDVDMenu()
    {
        // creates a keyboard object to read input
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** DVD Menu ***");
        System.out.println(" (1)Create DVD");
        System.out.println(" (2)Update DVD");
        System.out.println(" (3)Remove DVD");
        System.out.println(" (4)List all DVDs");
        System.out.println(" (5)Show Information about a DVD");
        System.out.println(" (6)Add copies to a DVD");
        System.out.println(" (7)List all copies of a DVD");
        System.out.println(" (8)Return");
        System.out.print("\n Make your choise: ");

        int choise3 = keyboard.nextInt();
        // return the choise that you have made
        return choise3;
    } 

}
